<?php
/*
* 频道管理
*/
class ChannelAction extends AdminBaseAction
{
    public function index()
    {
        $this->lists();
    }

    public function lists()
    {
        $m = M('channel');
        $items = $m->where('parent_id=0')->select();

        foreach ($items as &$item) {
            $childitems = $m->where('parent_id=' . $item['id'])->select();
            $item['child'] = $childitems;
        }

        $this->assign('channellist', $items);
        $this->display('list');
    }

    public function add()
    {
        $this->display('edit');
    }

    public function edit()
    {
        $id = $_GET['id'];

        $m = M('channel');
        $item = $m->where('id=' . $id)->find();

        $this->assign('edititem', $item);
        $this->display('edit');
    }

    public function del()
    {
        $id = $_GET['id'];
        echo $id;
    }


    public function post_edit()
    {
        $m = M("channel");
        $m->create();
        if (empty($m->en_title)) {
            import('@.Utils.Pinyin');
            $pinyin = new Pinyin();

            $py = $pinyin->get_pinyin_array($m->title, true);
            $m->en_title = $py[0];
        }
        $count = $m->save();
        if ($count)
            $this->redirect('Channel/lists');
        else
            echo 'error';
    }

    public function post_add()
    {
        $m = M("channel");
        $m->create();
        if (empty($m->en_title)) {
            import('@.Utils.Pinyin');
            $pinyin = new Pinyin();

            $py = $pinyin->get_pinyin_array($m->title, true);
            $m->en_title = $py[0];
        }
        $count = $m->add();
        if ($count)
            $this->redirect('Channel/lists');
        else
            echo 'error';
    }
}

?>